/**
 * Created with IntelliJ IDEA
 * Description:
 * User:34398
 * Date:2024-04-05
 * Time:17:23
 */

import java.util.Arrays;

public class MyStack {

    int[] arr;
    int useSize;//是栈的容量
    int top;

    public MyStack() {
        this.arr = new int[10];
        this.useSize = 10;
        this.top = 0;//代表当前元素个数，当前下标恰好没有元素
    }

    public void push(int val) {

        if (this.top == this.useSize) {
            this.arr = Arrays.copyOf(arr, this.useSize * 2);//要调用拷贝方法，要用类名Arrays点出来啊啊啊啊啊啊啊
            this.useSize = this.useSize * 2;
        }
        this.arr[this.top] = val;
        this.top++;

    }

    //判断是否栈满
    public boolean isFull() {
        return this.top == this.useSize ? true : false;
    }

    public int pop() {//出栈
        this.top--;
        return this.arr[this.top];
    }

    public int peek() {

        return this.arr[this.top-1];
    }

    public boolean empty() {

        return this.top==0?true:false;
    }

    public static void main(String[] args) {
        MyStack myStack=new MyStack();
        myStack.push(1);
        myStack.push(2);
        myStack.push(3);
        myStack.push(4);
        myStack.push(5);
        myStack.push(6);
        myStack.push(7);
        myStack.push(8);
        myStack.push(9);
        myStack.push(10);
        myStack.pop();
        int s=myStack.peek();
        System.out.println(s);
    }
}

